/*
 * @Author: xws 1043495328@qq.com
 * @Date: 2023-07-24 15:12:16
 * @LastEditors: xws 1043495328@qq.com
 * @LastEditTime: 2023-07-28 09:31:02
 * @FilePath: \vue3-admin-template\src\api\product\attr\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//商品属性API
import request from '@/utils/request'
import type { CategoryResponseData, AttrResponseData } from './type'
enum API {
  C1_URL = '/admin/product/getCategory1',
  C2_URL = '/admin/product/getCategory2/',
  C3_URL = '/admin/product/getCategory3/',
  ATTR_URL = '/admin/product/attrInfoList/',
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  DELETE_URL = '/admin/product/deleteAttr/',
}
//获取一级接口方法
export const reqC1 = () => request.get<any, CategoryResponseData>(API.C1_URL)
//获取二级接口方法
export const reqC2 = (category1Id: number | string) =>
  request.get<any, CategoryResponseData>(API.C2_URL + category1Id)
//获取三级接口方法
export const reqC3 = (category2Id: number | string) =>
  request.get<any, CategoryResponseData>(API.C3_URL + category2Id)
//获取分类下已有的属性与属性值接口方法
export const reqAttr = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) =>
  request.get<any, AttrResponseData>(
    API.ATTR_URL + `${category1Id}/${category2Id}/ ${category3Id}`,
  )
// 新增或者修改已有的属性接口
export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDATEATTR_URL, data)
export const reqRemoveAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETE_URL + attrId)
